-- AiouliyaStatue
-- Created by chengb Dec/30/2015
-- 艾欧利亚雕像格子

-- 对话总数
local TOTAL_DIALOG_TIMES = 5;

-- 初始化
function initAiouliyaStatue(self)
    self.item:removeAllChildren();

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 根据点击次数获取对话内容
            self.times = self.times or 1;
            
            if self.times > TOTAL_DIALOG_TIMES then
                -- 次数超过了，不处理
                return;
            end
            
            local dialog = getLocStr("aiouliya_statue_dialog" .. self.times);

            local function okFunc()
                if self.gridData.state == GRID_STATE_DISABLE then
                    -- 已经失效，不处理
                    return;
                end

                if self.times <= TOTAL_DIALOG_TIMES then
                    return;
                end

                -- 播放奖励光效
                local function playEventEffect()
                    playBuildingStrongLight(self);

                    -- 执行奖励
                    local pos = self.gridData:getPos();
                    DungeonActionM.go("do_building_bonus", pos);
                end
                performWithDelay(self, playEventEffect, 0.5);
            end

            self:openBuildingView(okFunc, nil, dialog);

            if self.times <= TOTAL_DIALOG_TIMES then
                self.times = self.times + 1;
            end
        end
    end

    local iconPath = getLevelItemIconPath("aiouliya_statue");
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
end
